package com.g001.model.powers;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

import com.g001.enums.BlockType;
import com.g001.enums.MessagePositionType;
import com.g001.model.GCharacter;
import com.g001.model.Player;
import com.g001.util.CachedResourceLoader;

public class MagicAction extends Action {	

	
	private MessageAction message;
	private GCharacter character;
	private Image image;
	private float srcy = 600;
	private int magic;
	
	public MagicAction(final GCharacter character){
		this.character = character;
		magic = bonus * BlockType.MAGIC_ADD.getPoints();
		image = CachedResourceLoader.getInstance().getImage("data/g001/backgroundAction.png").getSubImage(0,266,512,100).getScaledCopy(2);
		image.rotate(90f);
		type = BlockType.MAGIC_ADD;
	}
	
	@Override
	public void render(GameContainer container, StateBasedGame game, Graphics g)
			throws SlickException {
		if(character instanceof Player) {
			// player
			g.setClip(0,200,200,400);
			image.draw(-2*image.getHeight(),srcy);
			g.clearClip();
		} else {
			// opponent
			g.setClip(container.getWidth()-200,200,200,400);
			image.draw(2*image.getHeight() ,srcy);
			g.clearClip();
		}
		message.render(container, game, g);
	}

	@Override
	public void update(GameContainer container, StateBasedGame game, int delta)
			throws SlickException {
		srcy -=1.5*delta;
		message.update(container, game, delta);
	}

	@Override
	public void action() {
		message = new MessageAction("Magic UP +"+magic, (character instanceof Player? MessagePositionType.LEFT:MessagePositionType.RIGHT));
		character.setCurrentAnimation(character.getCharacterType().getMagicAnim());
		message.action();
		character.getMagic().add(magic);
	}
	
	@Override
	public void setBonus(final int bonus){
		this.bonus = bonus;
		magic *= bonus;
	}

	@Override
	public boolean isFinished() {
		return message.isFinished();
	}

}
